import React, { Component } from 'react'
import { HashRouter as Router, Route, Redirect, Switch } from 'react-router-dom'
import routesMap from '@/router/routesMap'
import Loadable from 'react-loadable'
import Loading from '@/routes/Loading'

const routes = [
    //首页
    {
        path: routesMap.login,
        component: Loadable({
            loader: () => import('@/routes/Login'),
            loading: Loading
        })
    },
    //首页
    {
        path: routesMap.home,
        component: Loadable({
            loader: () => import('@/routes/Home'),
            loading: Loading
        })
    },
    //地图
    {
        path: routesMap.map,
        component: Loadable({
            loader: () => import('@/routes/Map'),
            loading: Loading
        })
    },
    //留言板
    {
        path: routesMap.messageBoard,
        component: Loadable({
            loader: () => import('@/routes/MessageBoard'),
            loading: Loading
        })
    },
]

export default class BaseLayout extends Component {

    render() {
        return (<Router>
            <Switch>

                <Redirect exact path="/" to={routesMap.messageBoard}></Redirect>

                {routes.map(
                    (route, idx) => {
                        const { exact, ...rest } = route
                        return (
                            <Route
                                key={idx}
                                {...rest}
                                {...this.props}
                                exact={!!exact}
                            />
                        )
                    }
                )}

                {/* Not Found */}
                <Route component={() => import('@/routes/NotFound')} />

            </Switch>
        </Router>)
    }

}
